package com.huizhonglm.diap.presenters.wallet;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.HttpImpl;
import com.huizhonglm.diap.api.model.wallet.RevenueInfoTotal;
import com.huizhonglm.diap.presenters.BasePresenter;
import com.huizhonglm.diap.ui.wallet.iView.RcmRevenueIView;

import org.xutils.http.RequestParams;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:53
 */
public class RcmRevenuePresenter extends BasePresenter {

    private RcmRevenueIView iView;

    public RcmRevenuePresenter(RcmRevenueIView iView) {
        this.iView = iView;
    }

    public void loadData(String userId){
        String uri=  API.HOST+ "/" + API.RCM_REVENUE+userId;
        RequestParams params = new RequestParams(uri);
//        x.http().post(params, new Callback.CommonCallback<String>() {
//            @Override
//            public void onSuccess(String result) {
//                if (!EmptyUtil.isEmpty(result)) {
//                    RevenueInfoTotal total = JSON.parseObject(result, RevenueInfoTotal.class);
//                    if (total!=null) {
//                        iView.onLoadDataSuccess(total);
//                    } else {
//                        iView.onLoadDataSuccess(null);
//                    }
//                } else {
//                    iView.onLoadDataSuccess(null);
//                }
//            }
//
//            @Override
//            public void onError(Throwable ex, boolean isOnCallback) {
//                iView.onLoadDataFailure();
//            }
//
//            @Override
//            public void onCancelled(CancelledException cex) {
//
//            }
//
//            @Override
//            public void onFinished() {
//
//            }
//        });
        HttpImpl.registerInstance().post("rcmRevenue", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    RevenueInfoTotal total = JSON.parseObject(result, RevenueInfoTotal.class);
                    if (total != null) {
                        iView.onLoadDataSuccess(total);
                    } else {
                        iView.onLoadDataSuccess(null);
                    }
                } else {
                    iView.onLoadDataSuccess(null);
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.onLoadDataFailure();
            }
        });
    }
}
